package org.rency.ues.engine.repository.impl;

import org.rency.ues.dal.dao.CertificationDao;
import org.rency.ues.dal.entity.CertificationDO;
import org.rency.ues.domain.model.CertificationDomain;
import org.rency.ues.domain.support.Certification;
import org.rency.ues.engine.converter.CertificationConverter;
import org.rency.ues.engine.repository.CertificationRepository;

import java.util.List;

public class CertificationRepositoryImpl implements CertificationRepository {

	private CertificationDao certificationDao;
	
	@Override
	public List<Certification> loadAll() throws Exception {
		return CertificationConverter.convert2(certificationDao.loadAll());
	}

	@Override
	public CertificationDomain get(int id) {
		return CertificationConverter.convert(certificationDao.get(id));
	}

	@Override
	public CertificationDomain getBySerialNo(String serialNo) {
		return CertificationConverter.convert(certificationDao.getBySerialNo(serialNo));
	}

	@Override
	public CertificationDomain getByEmail(String orgiEmail) {
		return CertificationConverter.convert(certificationDao.getByEmail(orgiEmail));
	}

	@Override
    public boolean save(CertificationDomain domain) {
        CertificationDO entity = CertificationConverter.convert(domain);
        boolean result = certificationDao.insert(entity) == 1;
        if(result){
            domain.setId(entity.getId());
        }
        return result;
    }

	@Override
	public boolean delete(int id) {
		return certificationDao.delete(id) == 1;
	}

	public void setCertificationDao(CertificationDao certificationDao) {
		this.certificationDao = certificationDao;
	}

}